var MongoClient = require('mongodb').MongoClient;
var dbname = 'test'
var collection = 'books'
var url = "mongodb://localhost:27017/" + dbname;
 
const options = {useUnifiedTopology:true}
MongoClient.connect(url, options, function(err, db) {
  if (err) throw err;
  console.log("数据库已创建!");
  var dbase = db.db(dbname);
  console.log(dbase)
    dbase.createCollection(collection, function (err, res) {
        if (err) throw err;
        console.log("创建集合!", collection);
        db.close();
    });
//   db.close();
});
